package com.oa.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.oa.security.custom.LoginUserInfoHelper;
import com.oa.system.mapper.SysUserMapper;
import com.oa.model.system.SysUser;
import com.oa.system.service.SysDeptService;
import com.oa.system.service.SysPostService;
import com.oa.system.service.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author cloud_oa
 * @since 2024-10-05
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    //@Autowired
    //private SysDeptService sysDeptService;
    //@Autowired
    //private SysPostService sysPostService;
    @Transactional
    @Override
    public void updateStatus(Long id, Integer status) {
        //SysUser sysUser = this.getById(id);
        //if(sysUser != null){
        //    if(status.intValue() == 1){
        //        sysUser.setStatus(status);
        //    }else{
        //        sysUser.setStatus(0);
        //    }
        //    this.updateById(sysUser);
        //}
        //根据id查询用户信息
        SysUser sysUser = baseMapper.selectById(id);
        //设置用户状态
        sysUser.setStatus(status);
        //调用方法进行修改
        baseMapper.updateById(sysUser);

    }

    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    @Override
    public SysUser getByUserName(String username) {
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUser::getUsername, username);
        SysUser sysUser = baseMapper.selectOne(wrapper);
        return sysUser;
        //return this.getOne(new LambdaQueryWrapper<SysUser>()
        //        .eq(SysUser::getUsername, username)
        //);
    }

    @Override
    public Map<String, Object> getCurrentUser() {
        //SysUser sysUser = sysUserMapper.selectById(LoginUserInfoHelper.getUserId());
        //Map<String,Object> map = new HashMap<>();
        //map.put("name",sysUser.getUsername());
        //map.put("phone",sysUser.getPhone());
        return null;
    }
}
